package a2022.a20220704;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author lenovo
 * @date 2022/7/4
 */
public class a {
    public static void main(String[] args) {
        minimumAbsDifference(new int[]{4,2,1,3});
    }
    public static List<List<Integer>> minimumAbsDifference(int[] arr) {
        int length = arr.length;
        ArrayList<List<Integer>> lists = new ArrayList<>();

        Arrays.sort(arr);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < length - 1; i++) {

            if (min == (arr[i + 1] - arr[i])) {
                ArrayList<Integer> list = new ArrayList<>();
                list.add(arr[i]);
                list.add(arr[i+1]);
                lists.add(list);
            }else if (min > (arr[i + 1] - arr[i])){
                min=arr[i + 1] - arr[i];
                lists.clear();
                ArrayList<Integer> list = new ArrayList<>();
                list.add(arr[i]);
                list.add(arr[i+1]);
                lists.add(list);
            }
        }

        return lists;

    }
}
